package com.java.simple.study.tool;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @author zhoujunlin
 * @date 2021/12/15
 * @desc
 **/
public final class UnsafeUtil {

    private static final Unsafe unsafe;

    static {
        try {
            final Field declaredField = Unsafe.class.getDeclaredField("theUnsafe");
            declaredField.setAccessible(true);
            unsafe = (Unsafe) declaredField.get(null);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    public static Unsafe getUnsafe() {
        return unsafe;
    }

}
